//
//  TableBarViewController.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/23.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "TableBarViewController.h"
#import "HWDBaseViewController.h"

@interface TableBarViewController ()<UINavigationControllerDelegate>

@property (nonatomic, strong) NSArray *nameArray;//VC前部分名称

@property (nonatomic, strong) NSArray *imageName;//按钮图片

@property (nonatomic, strong) NSArray *titleArr;//按钮名称


@end

@implementation TableBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self  setView];
}

- (void)setView
{
    //循环将VC 按钮图片 昵称 加到TableBar上
    NSMutableArray *viewArray = [NSMutableArray array];
    for (int i = 0; i < self.nameArray.count;++i )
    {
        NSString *className = [NSString stringWithFormat:@"%@ViewController",self.nameArray[i]] ;
        Class myClass = NSClassFromString(className);
        HWDBaseViewController *vc = [[myClass alloc]init];
        
        UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:vc];
        navigation.delegate = self;
        
        vc.tabBarItem = [[UITabBarItem alloc]initWithTitle:self.titleArr[i] image:[[UIImage imageNamed:[NSString stringWithFormat:@"%@",self.imageName[i]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:[NSString stringWithFormat:@"%@_sel",self.imageName[i]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        
        [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#757575"]} forState:UIControlStateNormal];
        [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:blueColor} forState:UIControlStateSelected];
        [viewArray addObject:navigation];
    }
    self.viewControllers = viewArray;
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENW, self.tabBar.frame.size.height)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.tabBar insertSubview:backView atIndex:0];
    self.tabBar.opaque = YES;
    self.tabBar.translucent = YES;
    
    
}

- (NSArray *)nameArray//tableBar VC前半部分
{
    if (!_nameArray)
    {
        _nameArray = @[@"Main",@"Order",@"My"];
    }
    return _nameArray;
}

- (NSArray *)imageName//tableBar 图片
{
    if (!_imageName) {
        _imageName = @[@"home",@"zuixin",@"my"];
    }
    return _imageName;
}

- (NSArray *)titleArr//tableBar 标题
{
    if (!_titleArr)
    {
        _titleArr = @[@"主页",@"订单",@"我的"];
    }
    return _titleArr;
}

@end
